#include "stdafx.h"
#include "BoundingSphere.h"
#include "Math.h"
#include "BoundingBox.h"

BoundingSphere::BoundingSphere(void)
{
	radius = 0.f;
	position = vector_3::Zero;
}
BoundingSphere::BoundingSphere(Vector3& position, float radius)
{
	this->position = position;
	this->radius = radius;
}

/*virtual*/ bool BoundingSphere::Intersects(IBoundingShape* other)
{
	switch (other->getType())
	{
	case BOUNDING_SHAPE_SPHERE:
		{
		BoundingSphere* pSphere = (BoundingSphere*)other;
		if (VectorHelper::distance(position, pSphere->position) < radius + pSphere->radius)
			return true;
		}
		return false;
	case BOUNDING_SHAPE_CUBE:
	{
		BoundingBox* box = (BoundingBox*)other;

		float dist_x = Math::distance(box->position.x, position.x);
		float dist_y = Math::distance(box->position.y, position.y);
		float dist_z = Math::distance(box->position.z, position.z);

		return dist_x < box->computeWidth() + radius && dist_y < box->computeHeight() + radius && dist_z < box->computeDepth() + radius;
	}
	}

	return false;
}